package com.yw.smartcityforjava.view;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.PagerAdapter;

import java.util.List;

public class MyPageAdapter extends PagerAdapter {
    private List<View> listView;
    private List<String> listTab;
    private Context context;

    public MyPageAdapter(List<View> listView, List<String> listTab, Context context) {
        this.listView = listView;
        this.listTab = listTab;
        this.context = context;
    }

    public void setListView(List<View> listView) {
        this.listView = listView;
    }

    public void setListTab(List<String> listTab) {
        this.listTab = listTab;
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return listTab.get(position);
    }

    @Override
    public int getCount() {
        return listView.size();
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        container.addView(listView.get(position));
        //加载数据
        return listView.get(position);
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView(listView.get(position));
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;

    }
}
